﻿using AntdUI;
using PosClient.Delegates;
using ReactiveUI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PosClient.Controls
{
    public partial class PayRow : Control, INotifyPropertyChanged
    {
        public PayRow()
        {
            InitializeComponent();
            InitEvent();
        }

        private void InitEvent()
        {
            this.panel_back.Click += (s, e) =>
            {
                RowClick.Invoke(this, e);
            };
            this.Click += (s, e) =>
            {
                RowClick.Invoke(this, e);
            };
            this.label_title.Click += (s, e) =>
            {
                RowClick.Invoke(this, e);
            };
            this.avatar_svg.Click += (s, e) =>
            {
                RowClick.Invoke(this, e);
            };
        }

        public event RowClickEventHandler RowClick;

        private string _Title;
        private string _Svg;
        private int _Index;
        private object _TagData;
        private Color _PanelColor;
        private bool _Check;


        [Description("标题"), Category("外观"), DefaultValue("")]
        public string Title
        {
            get => _Title;
            set
            {
                if (_Title == value) return;
                _Title = value;
                label_title.Text = _Title;
                Invalidate();
                NotifyPropertyChanged();
            }
        }


        [Description("Svg图标"), Category("外观"), DefaultValue("")]
        public string Svg
        {
            get => _Svg;
            set
            {
                if (_Svg == value) return;
                _Svg = value;
                avatar_svg.ImageSvg = _Svg;
                Invalidate();
                NotifyPropertyChanged();
            }
        }

        [Description("索引"), Category("外观"), DefaultValue(-1)]
        public int Index
        {
            get => _Index;
            set
            {
                if (_Index == value) return;
                _Index = value;
                Invalidate();
                NotifyPropertyChanged();
            }
        }

        [Description("自定义数据"), Category("外观"), DefaultValue(null)]
        public object TagData
        {
            get => _TagData;
            set
            {
                if (_TagData == value) return;
                _TagData = value;
                Invalidate();
                NotifyPropertyChanged();
            }
        }

        [Description("背景色"), Category("外观"), DefaultValue(null)]
        public Color PanelColor
        {
            get => _PanelColor;
            set
            {
                if (_PanelColor == value) return;
                _PanelColor = value;
                panel_back.Back = _PanelColor;
                Invalidate();
                NotifyPropertyChanged();
            }
        }

        [Description("选中"), Category("外观"), DefaultValue(false)]
        public bool Check
        {
            get => _Check;
            set
            {
                if (_Check == value) return;
                _Check = value;
                panel_back.Back = _Check ? Color.FromArgb(224, 228, 229) : Color.White;
                Invalidate();
                NotifyPropertyChanged();
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); //实现通知刷新
        }
    }
}
